#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
@file_name: starting_server_and_listening_for_a_connection.py
@date: 2025-07-28 18:00
@author: Falling Snow
@desc: 创建监听一个连接的服务器
"""

import socket

if __name__ == '__main__':
    # create a TCP server socket 创建一个 TCP 服务器的socket
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

    server_address = ("127.0.0.1", 8000)
    # 设置这个socket的address和port
    server_socket.bind(server_address)
    # 开启监听
    server_socket.listen()

    connection, client_address = server_socket.accept()
    print(f"我已经链接到了{client_address}")
